package reflect;

import java.lang.reflect.Constructor;
import java.lang.reflect.Method;
import java.util.Scanner;

public class ReflectDemo4 {
    public static void main(String[] args) throws Exception {
        Person p=new Person();
        p.dance();


        Scanner scanner=new Scanner(System.in);
        System.out.println("请输入要实例化的对象");
        String className=scanner.nextLine();
        System.out.println("请输入方法名");
        String methodName=scanner.nextLine();

        Class cls=Class.forName(className);
        Constructor constructor=cls.getConstructor(String.class,int.class);
        Object obj=constructor.newInstance("小王",15);


        Method method=cls.getMethod(methodName);
        method.invoke(obj);


    }
}
